﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace MenuGame2DXNA
{
    public abstract class Sprite
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="Sprite"/> class.
        /// </summary>
        /// <param name="_inputTexture">The _input texture.</param>
        /// <param name="_position">The _position.</param>
        protected Sprite(Texture2D[] _inputTexture, Vector2 _position)
        {
            Color = Color.White;
            Size = new Vector2(0,0);
            Textture2d = _inputTexture;
            Position = _position;
            currentFrame = 0;
            PositionStart = Position;
        }

        protected Sprite(Texture2D _inputTexture, Vector2 _position)
        {
            Color = Color.White;
            Size = new Vector2(0, 0);
            Textture2d = new Texture2D[1];
            Textture2d[0] = _inputTexture;
            Position = _position;
            currentFrame = 0;
            PositionStart = Position;
            ntextture2d = 1;
        }

        /// <summary>
        /// Gets or sets màu của sprite.
        /// </summary>
        /// <value>
        /// The color.
        /// </value>
        public Color Color { get; set; }

        private Vector2 positionStart;

        /// <summary>
        /// Gets or sets the position start.
        /// </summary>
        /// <value>
        /// The position start.
        /// </value>
        public Vector2 PositionStart
        {
            get { return positionStart; }
            set { positionStart = value; }
        }
        /// <summary>
        /// Gets or sets kích thước của sprite
        /// </summary>
        /// <value>
        /// The size.
        /// </value>
        public Vector2 Size { get; set; }

        /// <summary>
        /// 
        /// </summary>
        private Texture2D[] _textture2d;
        /// <summary>
        /// Gets or sets the textture2d.
        /// </summary>
        /// <value>
        /// The textture2d.
        /// </value>
        public Texture2D[] Textture2d
        {
            get { return _textture2d; }
            set
            {
                _textture2d = value;
                ntextture2d = _textture2d.Length;              
            }
        }

        /// <summary>
        /// Gets or sets tốc độ của frame
        /// </summary>
        /// <value>
        /// The speeds.
        /// </value>
        public int Speeds { get; set; }

        /// <summary>
        /// Gets or sets số lượng texture.
        /// </summary>
        /// <value>
        /// The ntextture2d.
        /// </value>
        public int ntextture2d { get; set; }

        /// <summary>
        /// Gets or sets vị trí pixcel trên màn hình.
        /// </summary>
        /// <value>
        /// The position.
        /// </value>
        public Vector2 Position { get; set; }


        /// <summary>
        /// Gets or sets frame hiện tại
        /// </summary>
        /// <value>
        /// The current frame.
        /// </value>
        public int currentFrame { get; set; }

        public int TimeSinceLastFrame { get; set; }


        /// <summary>
        /// Gets or sets Tên của sprite
        /// </summary>
        /// <value>
        /// The name.
        /// </value>
        public string Name { get; set; }
        /// <summary>
        /// Updates the specified game time.
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        public virtual void Update(GameTime gameTime)
        {                   
            
        }
        /// <summary>
        /// Draws the specified game time.
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        /// <param name="spriteBatch">The sprite batch.</param>
        public virtual void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            
            Rectangle rect;
            if (Size.X == 0)
            {
                 rect = new Rectangle((int)Position.X , (int)Position.Y, Textture2d[currentFrame].Width, Textture2d[currentFrame].Height);
            }
            else
            {
                 rect = new Rectangle((int)Position.X, (int)Position.Y, (int)Size.X,(int) Size.Y);
            }

            spriteBatch.Draw(Textture2d[currentFrame], rect, Color);
        }        

    }
}
